home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / rxdoscmd.zip / RXDOSFOR.ASM < prev    next >
Assembly Source File  |  1993-06-06  |  18KB  |  398 lines

  1.         TITLE   'For - RxDOS Command Shell For Function'
  2.         PAGE 59, 132
  3.         .LALL
  4.  
  5.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  6.         ;  RxDOS Command Shell For                                      ;
  7.         ;...............................................................;
  8.  
  9.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  10.         ;  Real Time Dos                                                ;
  11.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  12.         ;                                                               ;
  13.         ;  This material  was created as a published version  of a DOS  ;
  14.         ;  equivalent product.   This program  logically  functions in  ;
  15.         ;  the same way as  MSDOS functions and it  is  internal  data  ;
  16.         ;  structure compliant with MSDOS 5.0                           ;
  17.         ;                                                               ;
  18.         ;  This product is distributed  AS IS and contains no warranty  ;
  19.         ;  whatsoever,   including  warranty  of   merchantability  or  ;
  20.         ;  fitness for a particular purpose.                            ;
  21.         ;                                                               ;
  22.         ;                                                               ;
  23.         ;  (c) Copyright 1990, 1992. Api Software and Mike Podanoffsky  ;
  24.         ;      All Rights Reserved Worldwide.                           ;
  25.         ;                                                               ;
  26.         ;  This product is protected under copyright laws and  may not  ;
  27.         ;  be reproduced  in whole  or in part, in any form  or media,  ;
  28.         ;  included but not limited to source listing, facimilie, data  ;
  29.         ;  transmission, cd-rom, or  floppy disk without the expressed  ;
  30.         ;  written consent of the author.                               ;
  31.         ;                                                               ;
  32.         ;  Licence for distribution in commercial use:                  ;
  33.         ;                                                               ;
  34.         ;  Api Software                                                 ;
  35.         ;  12 South Walker Street                                       ;
  36.         ;  Lowell,  MA   01851                                          ;
  37.         ;  508/ 454-4961.                                               ;
  38.         ;                                                               ;
  39.         ;...............................................................;
  40.  
  41.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  42.         ;  RxDOS Command Shell                                          ;
  43.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  44.         ;                                                               ;
  45.         ;  Programmer's Notes:                                          ;
  46.         ;                                                               ;
  47.         ;  Command Shell consists of  two parts bound  together into a  ;
  48.         ;  single executable load.  There  exists  a  single  resident  ;
  49.         ;  command shell which is accessible by an Int 2Eh.             ;
  50.         ;                                                               ;
  51.         ;...............................................................;
  52.  
  53.         include rxdosmac.asm
  54.         include rxdosdef.asm
  55.         include rxdoscin.asm
  56.  
  57.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  58.         ;  RxDOS Command Shell                                          ;
  59.         ;...............................................................;
  60.  
  61. RxDOSCMD SEGMENT PUBLIC 'CODE'
  62.          assume cs:RxDOSCMD, ds:RxDOSCMD, es:RxDOSCMD, ss:RxDOSCMD
  63.  
  64.         public _For
  65.  
  66.         extrn CheckOptOneArg                            : near
  67.         extrn CountArgs                                 : near
  68.         extrn CmndLookup                                : near
  69.         extrn CmndError_SyntaxError                     : near
  70.         extrn CRLF                                      : near
  71.         extrn DisplayErrorMessage                       : near
  72.         extrn DisplayLine                               : near
  73.         extrn DisplayPrompt                             : near
  74.         extrn _CopyString                               : near
  75.         extrn ReplaceForVariables                       : near
  76.         extrn _InternalCommandParser                    : far
  77.  
  78.         extrn RxDOS_DTA                                 : near
  79.         extrn RxDOS_ForArgs                             : near
  80.         extrn RxDOS_WorkArea                            : near
  81.         extrn _lowerCase                                : near
  82.         extrn _lowerCaseString                          : near
  83.  
  84.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  85.         ;  FOR %variable IN (set) DO command [command-parameters]       ;
  86.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  87.         ;                                                               ;
  88.         ;  Replace %var in command.                                     ;
  89.         ;                                                               ;
  90.         ;...............................................................;
  91.  
  92. _For:
  93.  
  94.         Entry
  95.         def __argarray, di
  96.         def __arg
  97.         def __cmdline
  98.         def __endrepeatArg
  99.         def _letter
  100.         def _nArgs
  101.         def _pathSep
  102.         def  _ArgAlloc
  103.  
  104.         defbytes _commandLine, 128
  105.         defbytes _replacement, 128
  106.  
  107. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  108. ;  get variable arg letter 
  109. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  110.  
  111.         call CountArgs                                  ; must have min of 8 args
  112.         cmp ax, 8                                       ; min args 
  113.         jge _For_08                                     ; if at leats 8 -->
  114.         jmp _ForError                                   ; else if less, syntax error -->
  115.  
  116. _For_08:
  117.         mov si, word ptr [ forVarIdent ][ di ]          ; point to arg
  118.         cmp byte ptr [ si ], '%'                        ; is arg a % variable ?
  119.         ifnz _ForError                                  ; if not, then syntax error -->
  120.  
  121.         mov al, byte ptr [ si + 1 ]                     ; get letter
  122.         call _lowerCase
  123.         cbw
  124.         storarg _letter, ax
  125.  
  126. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  127. ;  check for 'in' argument
  128. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  129.  
  130.         mov si, word ptr [ forInArg ][ di ]             ; point to next arg
  131.         mov di, offset RxDOS_ForArgs
  132.         call CmndLookup                                 ; lookup command
  133.         ifc _ForError                                   ; if not, then syntax error -->
  134.  
  135.         cmp bx, _IN                                     ; 'in' returns a zero
  136.         ifnz _ForError                                  ; if not 'in', then syntax error -->
  137.  
  138. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  139. ;  check for ( argument
  140. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  141.  
  142.         getarg di, __argarray
  143.         add di, forInStartParen + 2
  144.         mov si, word ptr [ di - 2 ]                     ; point to next arg
  145.         cmp byte ptr [ si ], '('                        ; is arg a ( variable ?
  146.         ifnz _ForError                                  ; if not, then syntax error -->
  147.  
  148.         storarg __arg, di                               ; di points to an argument
  149.  
  150. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  151. ;  search for ) do ...
  152. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  153.  
  154.         dec di
  155.         dec di
  156.  
  157. _ForSearchForParen:
  158.         inc di
  159.         inc di
  160.         mov si, word ptr [ di ]                         ; point to next arg
  161.         or si, si                                       ; end of args ?
  162.         ifz _ForError                                   ; if not, then syntax error -->
  163.  
  164.         cmp byte ptr [ si ], ')'                        ; is arg a ) variable ?
  165.         jnz _ForSearchForParen                          ; keep looking -->
  166.  
  167. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  168. ;  search for last ) in case ))) ...
  169. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  170.  
  171. _ForSearchForDoLastParen:
  172.         inc di
  173.         inc di
  174.         mov si, word ptr [ di ]                         ; point to next arg
  175.         or si, si                                       ; end of args ?
  176.         ifz _ForError                                   ; if not, then syntax error -->
  177.  
  178.         cmp byte ptr [ si ], ')'                        ; is arg a ) variable ?
  179.         jz _ForSearchForDoLastParen                     ; keep looking -->
  180.  
  181. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  182. ;  test for a 'do' argument
  183. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  184.  
  185. _ForSearchForDo:
  186.         push di
  187.         mov di, offset RxDOS_ForArgs
  188.         call CmndLookup                                 ; lookup command
  189.         pop di                                          ; restore arg pointer
  190.         ifc _ForError                                   ; if not legit, syntax error -->
  191.  
  192.         cmp bx, _DO                                     ; 'do' returns a 1
  193.         ifnz _ForError                                  ; if not found -->
  194.  
  195.         inc di
  196.         inc di
  197.         storarg __cmdline, di                           ; where command line is
  198.  
  199.         sub di, 4
  200.         storarg __endrepeatArg, di                      ; end repeat arg
  201.  
  202. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  203. ;  sequentially walk through each arg
  204. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  205.  
  206. _ForNext:
  207.         getarg bx, __arg                                ; point to arg list
  208.         cmp bx, word ptr [ __endrepeatArg ][ bp ]       ; end repeat arg ?
  209.         jz _ForReturn                                   ; if at end, exit -->
  210.  
  211.         mov cx, word ptr [ bx + 2 ]
  212.         sub cx, word ptr [ bx ]                         ; distance to copy
  213.         mov si, word ptr [ bx ]
  214.         lea di, offset [ _replacement ][ bp ]
  215.         call _buildForArgList                           ; build arg list
  216.  
  217.         storarg _nArgs, cx                              ; how many args in curr element list
  218.         storarg _pathSep, dx                            ; fixed portion of argument
  219.         mov word ptr [ _ArgAlloc ][ bp ], offset RxDOS_WorkArea
  220.  
  221. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  222. ;  redefine command line
  223. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  224.  
  225. _ForNext_22:
  226.         getarg di, __cmdline                            ; ptr->arg array where command line begins
  227.         mov si, word ptr [ di ]                         ; ptr-> text
  228.         lea di, offset [ _commandLine ][ bp ]
  229.         call _CopyString                                ; get command line
  230.  
  231.         cmp word ptr [ _nArgs ][ bp ], 0000             ; no special args ?
  232.         jz _ForNext_26                                  ; no, use arg as available -->
  233.  
  234.         mov si, word ptr [ _ArgAlloc ][ bp ]
  235.         getarg di, _pathSep
  236.         call _CopyString                                ; get arg ...
  237.  
  238.         mov word ptr [ _ArgAlloc ][ bp ], si
  239.         dec word ptr [ _nArgs ][ bp ]                   ; how many remaining ?
  240.  
  241. _ForNext_26:
  242.         mov al, byte ptr [ _letter ][ bp ]
  243.         lea bx, offset [ _replacement ][ bp ]
  244.         lea si, offset [ _commandLine ][ bp ]
  245.         call ReplaceForVariables                        ; replace variable letter
  246.  
  247.         call DisplayPrompt                              ; display prompt
  248.  
  249.         lea dx, offset [ _commandLine ][ bp ]
  250.         call DisplayLine                                ; echo line
  251.         call CRLF
  252.  
  253.         lea si, offset [ _commandLine ][ bp ]
  254.         call _InternalCommandParser                     ; reparse remainder of line
  255.  
  256.         cmp word ptr [ _nArgs ][ bp ], 0000             ; arg list ?
  257.         jnz _ForNext_22                                 ; yes, continue using args -->
  258.  
  259. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  260. ;  get next argument
  261. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  262.  
  263. _ForNext_36:
  264.         add word ptr [ __arg ][ bp ], 2                 ; point to next arg
  265.         jmp _ForNext
  266.  
  267. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  268. ;  error
  269. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  270.  
  271. _ForError:
  272.         mov dx, offset CmndError_SyntaxError
  273.         call DisplayErrorMessage
  274.  
  275. _ForReturn:
  276.         Return
  277.  
  278.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  279.         ;  Build For Arg List                                           ;
  280.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  281.         ;                                                               ;
  282.         ;  This routine tries to determine how many arguments will be   ;
  283.         ;  fed to a 'for' statement loop.  A list is built              ;
  284.         ;                                                               ;
  285.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  286.         ;                                                               ;
  287.         ;  Input:                                                       ;
  288.         ;   si     pointer to argument                                  ;
  289.         ;   di     pointer to where to return first arg                 ;
  290.         ;   cx     length of argument                                   ;
  291.         ;                                                               ;
  292.         ;  Return:                                                      ;
  293.         ;   di     first arg is returned at [di]                        ;
  294.         ;   dx     constant part of arg (if more than one arg )         ;
  295.         ;   cx     # arg pointers that follow in arg list               ;
  296.         ;                                                               ;
  297.         ;...............................................................;
  298.  
  299. _buildForArgList:
  300.  
  301.         Entry
  302.         def  _firstArg, di
  303.         def  _pathSep, di
  304.         def  _nArgs, 0000
  305.         def  _ArgAlloc
  306.  
  307. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  308. ;  copy argument
  309. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  310.  
  311.         rep movsb
  312.         storarg _pathSep, di
  313.  
  314.         xor ax, ax
  315.         stosb                                           ; null terminate
  316.  
  317. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  318. ;  if arg contains wild cards, try to expand arg name
  319. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  320.  
  321.         getarg si, _firstArg
  322.  
  323. _buildForArgList_04:
  324.         lodsb
  325.         cmp al, '?'
  326.         jz _buildForArgList_06
  327.         cmp al, '*'
  328.         jz _buildForArgList_06
  329.         or al, al                                       ; end of string ?
  330.         jnz _buildForArgList_04                         ; keep searching -->
  331.  
  332.         jmp _buildForArgList_36                         ; exit with argument -->
  333.  
  334. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  335. ;  break up name into path\filename
  336. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  337.  
  338. _buildForArgList_06:
  339.         dec si
  340.         cmp si, word ptr [ _firstArg ][ bp ]
  341.         jz _buildForArgList_10
  342.         cmp byte ptr [ si ], '\'
  343.         jz _buildForArgList_08
  344.         cmp byte ptr [ si ], ':'
  345.         jnz _buildForArgList_06
  346.  
  347. _buildForArgList_08:
  348.         inc si
  349.  
  350. _buildForArgList_10:
  351.         storarg _pathSep, si
  352.  
  353. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  354. ;  find first
  355. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  356.  
  357.         mov word ptr [ _ArgAlloc ][ bp ], offset RxDOS_WorkArea
  358.  
  359.         getarg dx, _firstArg
  360.         Int21 FindFirstFile                             ; any found ?
  361.         jc _buildForArgList_36                          ; if none -->
  362.  
  363. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  364. ;  save argument
  365. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  366.  
  367. _buildForArgList_22:
  368.         mov si, offset [ RxDOS_DTA. findFileName ]
  369.         getarg di, _ArgAlloc
  370.         call _CopyString
  371.  
  372.         storarg _ArgAlloc, di
  373.         inc word ptr [ _nArgs ][ bp ]
  374.  
  375.         Int21 FindNextFile                              ; next ?
  376.         jnc _buildForArgList_22                         ; if next found -->
  377.  
  378. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  379. ;  get first arg
  380. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  381.  
  382.         getarg di, _ArgAlloc
  383.         mov word ptr [ di ], 0000                       ; save terminator
  384.  
  385. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  386. ;  return
  387. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  388.  
  389. _buildForArgList_36:
  390.         getarg si, _firstArg
  391.         getarg dx, _pathSep
  392.         getarg cx, _nArgs
  393.         or cx, cx
  394.         Return
  395.  
  396. RxDOSCMD                        ENDS
  397.                                 END
  398.